<?php
namespace backend\models\activeRecords;

use MongoDB\Driver\Server;
use Yii;
use yii\db\ActiveRecord;
use yii\helpers\Json;

/**
 * This is the model class for table "{{%t_server}}".
 *
 * @property int $server_id
 * @property int $game_id 游戏ID
 * @property string $server_no 接口用游戏编号
 * @property string $server_name 服务器名
 * @property string $server_logo 服务器logo
 * @property string $server_logo2
 * @property string $server_logo3
 * @property string $server_depict 服务器描述
 * @property string $server_line
 * @property int $server_state 服务器状态
 * @property string $server_trunon_date 开服日期
 * @property int $server_trunon_hour 开服时间
 * @property string $server_login_gateway 登录地址
 * @property string $server_pay_gateway 支付地址
 * @property int $server_is_show 是否显示服务器
 * @property int $server_is_best
 * @property int $server_is_pay 是否允许支付
 * @property int $server_sort 排序
 * @property int $game_api_login_id 游戏充值api表的ID
 * @property int $game_api_recharge_id 游戏充值API表的ID
 * @property int $game_api_role_id 游戏角色查询API表的ID
 * @property string $game_api_tryplay_id 试玩角色查询接口id
 */
class TServer extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%t_server}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['game_id', 'server_state', 'server_trunon_hour', 'server_is_show', 'server_is_best', 'server_is_pay', 'server_sort', 'game_api_login_id', 'game_api_recharge_id', 'game_api_role_id', 'game_api_tryplay_id'], 'integer'],
            [['server_no', 'server_name', 'server_logo', 'server_logo2', 'server_logo3', 'server_line', 'server_trunon_date'], 'string', 'max' => 50],
            [['server_depict'], 'string', 'max' => 255],
            [['server_login_gateway', 'server_pay_gateway'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'server_id' => Yii::t('app', 'Server ID'),
            'game_id' => Yii::t('app', '游戏ID'),
            'server_no' => Yii::t('app', '接口用游戏编号'),
            'server_name' => Yii::t('app', '服务器名'),
            'server_logo' => Yii::t('app', '服务器logo'),
            'server_logo2' => Yii::t('app', 'Server Logo2'),
            'server_logo3' => Yii::t('app', 'Server Logo3'),
            'server_depict' => Yii::t('app', '服务器描述'),
            'server_line' => Yii::t('app', 'Server Line'),
            'server_state' => Yii::t('app', '服务器状态'),
            'server_trunon_date' => Yii::t('app', '开服日期'),
            'server_trunon_hour' => Yii::t('app', '开服时间'),
            'server_login_gateway' => Yii::t('app', '登录地址'),
            'server_pay_gateway' => Yii::t('app', '支付地址'),
            'server_is_show' => Yii::t('app', '是否显示服务器'),
            'server_is_best' => Yii::t('app', 'Server Is Best'),
            'server_is_pay' => Yii::t('app', '是否允许支付'),
            'server_sort' => Yii::t('app', '排序'),
            'game_api_login_id' => Yii::t('app', '游戏充值api表的ID'),
            'game_api_recharge_id' => Yii::t('app', '游戏充值API表的ID'),
            'game_api_role_id' => Yii::t('app', '游戏角色查询API表的ID'),
            'game_api_tryplay_id' => Yii::t('app', '试玩角色查询接口id'),
        ];
    }

    public static function getServerList($game_id){
        $serverInfo = TServer::find()
            ->where('game_id = :game_id',[':game_id'=>$game_id])
            ->all();
        $serverList = [];
        foreach($serverInfo as $value){
            $serverList[$value->server_id] = $value->server_name;
        }
        return $serverList;
    }

}
